<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>货主注册 - 航运物流系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }
        
        .container {
            background: rgba(255, 255, 255, 0.95);
            padding: 40px;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        
        .logo {
            text-align: center;
            margin-bottom: 30px;
        }
        
        .logo h1 {
            color: #333;
            font-size: 24px;
            margin-bottom: 10px;
        }
        
        .logo p {
            color: #666;
            font-size: 14px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: 500;
        }
        
        .form-group input {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid #e1e1e1;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
        }
        
        .form-group input:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }
        
        .btn {
            width: 100%;
            padding: 12px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        
        .links {
            text-align: center;
            margin-top: 20px;
            color: #666;
        }
        
        .links a {
            color: #667eea;
            text-decoration: none;
            margin: 0 5px;
        }
        
        .links a:hover {
            text-decoration: underline;
        }
        
        .ship-icon {
            font-size: 48px;
            color: #667eea;
            margin-bottom: 15px;
        }
        
        .error-message {
            color: #e74c3c;
            margin-top: 15px;
            font-size: 14px;
            display: none;
        }
        
        .success-message {
            color: #27ae60;
            margin-top: 15px;
            font-size: 14px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="logo">
            <div class="ship-icon">📦</div>
            <h1>货主注册</h1>
            <p>航运物流管理系统</p>
        </div>
        
        <form id="registerForm">
            <div class="form-group">
                <label for="name">姓名</label>
                <input type="text" id="name" name="name" required placeholder="请输入您的姓名">
            </div>
            
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required placeholder="请输入密码">
            </div>
            
            <button type="submit" class="btn">注册</button>
            
            <div class="error-message" id="errorMessage"></div>
            <div class="success-message" id="successMessage"></div>
        </form>
        
        <div class="links">
            <a href="user_login.html">已有账户？立即登录</a>
            <a href="index.html">返回首页</a>
        </div>
    </div>

    <script>
        // 注册表单提交
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const name = document.getElementById('name').value;
            const password = document.getElementById('password').value;
            const errorMessage = document.getElementById('errorMessage');
            const successMessage = document.getElementById('successMessage');
            
            // 发送注册请求到后端
            fetch('http://172.21.136.66:8080/user/add', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body: `username=${encodeURIComponent(name)}&password=${encodeURIComponent(password)}`
            })
            .then(response => response.json())
            .then(data => {
                if (data.code === '0') {
                    successMessage.textContent = '注册成功！';
                    successMessage.style.display = 'block';
                    errorMessage.style.display = 'none';
                    
                    // 清空表单
                    document.getElementById('name').value = '';
                    document.getElementById('info').value = '';
                    document.getElementById('password').value = '';
                    
                    // 3秒后跳转到登录页面
                    setTimeout(() => {
                        window.location.href = 'user_login.html';
                    }, 3000);
                } else {
                    errorMessage.textContent = '注册失败：' + (data.message || '未知错误');
                    errorMessage.style.display = 'block';
                    successMessage.style.display = 'none';
                }
            })
            .catch(error => {
                errorMessage.textContent = '网络错误，请稍后重试';
                errorMessage.style.display = 'block';
                successMessage.style.display = 'none';
            });
        });
    </script>
</body>
</html>